
* model-based survival estimates including non-manipulative mediation

use book-basedata-replication, clear
stcox manip2 nomanip2 prevcris2 viol2 crisdur2 jointdem victory2 contig2 ///
	if _t<3650, strata(order5) cluster(dyadno) efron nohr texp(_t) tvc(manip2 prevcris2 nomanip2)

*calculate mean of each variable
foreach var of varlist med2 prevcris2 viol2 crisdur2 jointdem victory2 contig2 {
quietly sum `var' if e(sample)
local s_`var'=r(mean)
display `s_`var''
}

*predict survival with manipulative mediation at means
scurve_tvc if _t<3650, at(manip2 1 nomanip2 0 prevcris2 `s_prevcris2' ///
	viol2 `s_viol2' crisdur2 `s_crisdur2' jointdem `s_jointdem' ///
	victory2 `s_victory2' contig2 `s_contig2') strata(order5) ///
	ties(efron) texp(_t) tvc(manip2 prevcris2 nomanip2) gen(s_manip) replace

*predict survival with no manipulative mediation at means
scurve_tvc if _t<3650, at(manip2 0 nomanip2 1 prevcris2 `s_prevcris2' ///
	viol2 `s_viol2' crisdur2 `s_crisdur2' jointdem `s_jointdem' ///
	victory2 `s_victory2' contig2 `s_contig2') strata(order5) ///
	ties(efron) texp(_t) tvc(manip2 prevcris2 nomanip2) gen(s_nomanip) replace

*predict survival without mediation at means
scurve_tvc if _t<3650, at(manip2 0 nomanip2 0 prevcris2 `s_prevcris2' ///
	viol2 `s_viol2' crisdur2 `s_crisdur2' jointdem `s_jointdem' ///
	victory2 `s_victory2' contig2 `s_contig2') strata(order5) ///
	ties(efron) texp(_t) tvc(manip2 prevcris2 nomanip2) gen(s_no) replace
	
*plot results for each stratum
local t=1
label var s_no`t' "Without mediation"	
label var s_manip`t' "Manipulative mediation"	
label var s_nomanip`t' "Non-manipulative mediation"	
twoway line s_*`t' _tscurve, c(J J J) lc(gs8 gs13 black) legend(col(1)) ///
	saving(strata`t', replace) t2title(`t' previous crises)
forvalues t=2/5 {
	label var s_no`t' "Without mediation"	
	label var s_manip`t' "Manipulative mediation"	
	label var s_nomanip`t' "Non-manipulative mediation"	
	twoway line s_*`t' _tscurve, c(J J J) lc(gs8 gs13 black) legend(off) ///
		saving(strata`t', replace) t2title(`t' previous crises)
}
grc1leg strata1.gph strata2.gph strata3.gph strata4.gph strata5.gph, ///
	ycommon leg(strata1.gph)
